package com.snts.synchronization.protocol.adapter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public abstract class StringBufferDefaultHandler extends DefaultHandler {

	private static final Log log = LogFactory.getLog(StringBufferDefaultHandler.class);
	
	protected StringBuffer stringBuffer = new StringBuffer();

	@Override
	public void characters(char[] ch, int start, int length) throws SAXException {
		stringBuffer.append(ch, start, length);
	}

	@Override
	public void endElement(String uri, String localName, String qName) throws SAXException {
		log.debug("endElement(qName=" + qName + " stringBuffer=" + stringBuffer + ");");
		doEndElement(uri, localName, qName, stringBuffer.toString());
		stringBuffer = new StringBuffer();
		super.endElement(uri, localName, qName);
	}
	
	protected abstract void doEndElement(String uri, String localName, String qName, String textValue) throws SAXException;

}
